#include <SDL.h>

#include "asserts.hpp"
#include "wm.hpp"

namespace {
SDL_Window* g_main_window;
SDL_GLContext g_gl_context;
SDL_Renderer* g_sdl_renderer;
}

namespace wm
{

manager::manager()
{
}

manager::~manager()
{
	if(g_main_window) {
		SDL_DestroyWindow(g_main_window);
		g_main_window = 0;
	}
}

SDL_Surface* get_video_surface()
{
	return SDL_GetWindowSurface(g_main_window);
}

void manager::create_window(int width, int height, int flags)
{
	g_main_window = SDL_CreateWindow("Elensefar", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width,height,flags);
	g_gl_context = SDL_GL_CreateContext(g_main_window);
	g_sdl_renderer = SDL_CreateRenderer(g_main_window, -1, SDL_RENDERER_ACCELERATED);
	int res = SDL_GL_MakeCurrent(g_main_window, g_gl_context);
	ASSERT_EQ(res, 0);
}

void swap_buffers()
{
	SDL_GL_SwapWindow(g_main_window);
}


}

